#!/usr/bin/env bash

# edit_file.sh

# This program is part of Leah (Language editor and helper).

# Leah is part of Faridayix, an artificially intelligent computer
# operating system.

# Copyright (C) 2010 Scott C. MacCallum
# scottmaccal@gmail.com

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

function edit_file
{
  clear

  printf "${bold_font}EDIT FILE${default_font}"

  print_working_directory

  printf "\n"
  printf "Do you see the file that you would like to edit? ${bold_font}"

  read see_file

  printf "${default_font}"

    if [[ "$see_file" == "yes" || "$see_file" == "y" ]]; then
      printf "\n"
      printf "What file would you like to edit? ${bold_font}"

      read file_name

      printf "${default_font}"

      clear

      printf "I will display ${bold_font}$file_name${default_font} shortly."
      printf "\n"
      printf "\n"
      printf "Use the ${bold_font}up${default_font} and ${bold_font}down${default_font} arrow keys on your computers keyboard to move through the file."
      printf "\n"
      printf "\n"
      printf "Press the ${reverse_font}${bold_font}q${default_font} key on your computers keyboard to end displaying ${bold_font}$file_name${default_font}."

      sleep 10

      clear

      nl --body-numbering=a --number-width=1 -s " " $file_name | less
      nl --body-numbering=a --number-width=1 -s " " $file_name

      printf "\n"
      printf "What line would you like to look at? ${bold_font}"
      
      read line_number

      printf "${default_font}"

      let lines=11

      declare -i file_section

      file_section=$line_number+$lines

      nl --body-numbering=a --number-width=1 -s " " $file_name | head -n $file_section
  
    else
      yes_or_no

      edit_file
    fi

  printf "\n"
  printf "What file would you like to edit? ${bold_font}"

  read file_name

  printf "${default_font}"
  printf "\n"

  nl --body-numbering=a --number-width=1 -s " " $file_name
  
  printf "\n"
  printf "What line would you like to look at? ${bold_font}"

  read line_number

  printf "${default_font}"
  printf "\n"
  printf "Would you like to edit this line or insert an empty line above it? ${bold_font}"
  
  read line_option

  printf "${default_font}"
  printf "\n"
}
#EOF
